<template>
  <div id="app">
    <!-- key的值一旦变化，就会发生组件的重载 -->
    <Topbar :key="toastKeyValue"></Topbar>
    <Header></Header>
    <router-view @updateKey="updateKey" />
    <Footer></Footer>
    <Login />
    <transition name="slide">
      <Toast v-show="isShowToast"></Toast>
    </transition>
  </div>
</template>
<script>
import Topbar from "./components/topbar.vue"
import Header from "./components/header.vue"
import Footer from "./components/footer.vue"
import Login from "./components/login.vue"
import Toast from "./components/Toast.vue"
import { jingpinApi } from "./request/api"
import { mapState } from "vuex"
export default {
  components: {
    Topbar, Header, Footer, Login, Toast
  },
  data() {
    return {
      toastKeyValue: 0,
    }
  },
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        // 如果两个路由地址不相等的话就重载页面
        if (newVal != oldVal) {
          this.toastKeyValue++
        }
      }
    }
  },
  computed: {
    ...mapState({
      isShowToast: state => state.toastStatus.isShowToast,
    })
  },
  methods:{
    updateKey(){
      this.toastKeyValue++
    }
  },
  created() {
    console.log("process",process.env.VUE_APP_BASE_URL);
  },

}
</script>

<style lang="less">
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
